package com.hei.service;

import com.hei.dao.BuserMapper;
import com.hei.pojo.Buser;
import com.hei.pojo.BuserExample;
import com.hei.pojo.BuserKey;
import com.hei.util.MD5;
import com.hei.util.uuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BuserServiceImpl implements BuserService {
    @Autowired
    private BuserMapper buserMapper;

    @Override
    public boolean isAccount(Buser user) {

        BuserExample example=new BuserExample();
        example.createCriteria().andAccountEqualTo(user.getAccount());
        List<Buser> users = buserMapper.selectByExample(example);
        if(users.size()>0){
            return true;
        }
        return false;
    }

    @Override
    public void insertUser(Buser user) {
        user.setId(uuid.getUUId());
        user.setPassword(MD5.getMD5(user.getPassword()));
        buserMapper.insert(user);
    }

    @Override
    public Buser selectUserByAccount(String account) {
        BuserExample example=new BuserExample();
        example.createCriteria().andAccountEqualTo(account);
        List<Buser> users = buserMapper.selectByExample(example);
        return users.get(0);
    }

    @Override
    public boolean loginSuccess(Buser user) {
        BuserExample example=new BuserExample();
        example.createCriteria().andAccountEqualTo(user.getAccount()).andPasswordEqualTo(MD5.getMD5(user.getPassword()));
        List<Buser> users = buserMapper.selectByExample(example);
        if(users.size()>0)return true;
        return false;
    }

}
